<template>
  <div class="page-container">
    <div class="msg"
      v-loading="true"
      element-loading-spinner="el-icon-loading">
    </div>
  </div>
</template>

<script type="text/javascript">
import { mapGetters } from 'vuex'
import { login } from '@/api/login'
import mixins from '@/components/account/mixins'
export default {
  name: 'ThirdLogin',
  mixins: [mixins],
  computed: {
    ...mapGetters(['appInfo'])
  },
  created () {
    const query = this.$route.query
    if (query.order_id) return
    this.onThirdLogin()
  },
  methods: {
    onThirdLogin () {
      const query = this.$route.query
      const params = {
        'type': query.type,
        'authCode': query.code, // 第三方登录授权码
        'code_verifier': query.code_verifier,
        'grantType': 'authorization_code', // 授权类型 client_credentials: 客户端凭证 authorization_code:授权码
        'channel': this.appInfo.channel, // 渠道信息
        'uuid': this.appInfo.uuid, // 设备信息
        'device_name': this.appInfo.device_name, // 设备名称
        'version': this.appInfo.version,
        'redirect_uri': query.redirectURI
      }
      login(params).then(res => {
        const data = res.data || {}
        data.isAutoLogin = true
        data.isLogin = true
        data.loginType = params.type + 'Login'
        this.onLoginFinish(data)
        this.$router.push('/usercenter')
      }).catch(() => {
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.page-container.bg-grey{
  display: block;
  width: 100%;
  margin-top: 0;
  background: #494a4f;
}
.msg {
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 14px;
  vertical-align: middle;
  height: 100vh;
  text-align: center;
  /deep/.el-loading-spinner {
    margin-top: -10px;
    i {
      font-size: 18px;
    }
  }
  /deep/.el-loading-mask {
    background: #494a4f;
  }
}
</style>
